import { createScene } from "./components/scene";
import { createCamera } from "./components/camera";
import { createCude } from "./components/cube";
import { createLights } from "./components/lights";
import { createRenderder } from "./systems/renderer";
import { Resizer } from "./systems/Resizer";
import { Loop } from "./systems/Loop";
class World {
  #scene; // 场景
  #camera; // 相机
  #renderer; // 渲染
  #loop; // 动画循环
  /**
   * @param {Element} container - 容器
   */
  constructor(container) {
    this.#scene = createScene();
    this.#camera = createCamera();
    this.#renderer = createRenderder();
    this.#loop = new Loop(this.#camera, this.#scene, this.#renderer);
    container.append(this.#renderer.domElement);
    const cube = createCude();
    this.#loop.addObjectToUpdatables(cube);
    const light = createLights();
    this.#scene.add(cube, light);
    new Resizer(container, this.#camera, this.#renderer);
  }

  /**
   * @description - 渲染函数
   */
  render() {
    this.#renderer.render(this.#scene, this.#camera);
  }

  /**
   * @description - 动画循环开始
   */
  start() {
    this.#loop.start();
  }

  /**
   * @description - 动画循环结束
   */
  stop() {
    this.#loop.stop();
  }
}

export { World };
